<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(__FILE__)) . '/appwap.php');



$daytime = time();
$condition_ev56_s = array( 
		'team_type' => 'seconds',
		"begin_time <  {$daytime}",
		"end_time > {$daytime}",
		);

$daytimenow_ev56_s = time();
/*判断预告，过期，秒杀，热销*/
$condition_ev56_s = array(
	'team_type' => 'seconds',
	"begin_time < $daytimenow_ev56_s ",
	"end_time > $daytimenow_ev56_s",
);


if($_GET['area']){
 $condition_ev56_s['area_id'] = $_GET['area'];
}

if($_GET['s']=="zk")
{
$order='ORDER BY sort_order DESC, market_price - team_price DESC, id DESC';
}
elseif($_GET['s']=="b")
{
$order='ORDER BY now_number DESC, id DESC';
}
elseif($_GET['s']=="jg")
{
$order='ORDER BY team_price DESC, id DESC';
}
else 
{
$order='ORDER BY sort_order DESC,begin_time DESC, id DESC';
}




/*echo $city_id; 判断城市*/
//$condition_ev56_s['city_ids'] = $city_id;
$condition_ev56_s = array(
	'city_id'=>$city['id'],
	'team_type' => 'seconds',
);

$group_id = abs(intval($_GET['gid']));
$fid_s = abs(intval($_GET['fid_s']));
/*大分类ID*/
if ($group_id<>0){$condition_ev56_s['group_id'] = $group_id;}
if ($fid_s<>0){$condition_ev56_s['sub_id'] = $fid_s;}


$size = !empty($size) ? $size : 10;

list($pagesize, $offset, $pagestring) = pagestring($count, $size,true);

$teams = DB::LimitQuery('team', array(
	'condition' => $condition_ev56_s,
	'order' => $order,
	'size' => $pagesize,
	'offset' => $offset,
));	 





/*区域列表*/
$area_list = DB::LimitQuery('category', array(
	'condition' => array(
		'zone' => 'area',
		'display' => 'Y',
		'fid'=>$city['id'],
),
	'order' => 'ORDER BY sort_order DESC',
));


   
//获取二级分类

function get_two_category($fid){
	  $row = DB::LimitQuery('category', array(
		'condition' => array(
			'zone' => 'group',
			'display' => 'y',
			'fid'=> $fid,
		),
			'order' => 'ORDER BY sort_order DESC',
		));
	$category = array();
	
	foreach($row as $val){
	   $category[$val['id']]['id']    = $val['id'];
	   $category[$val['id']]['name']  = $val['name'];
	}
     return $category;	
}   

//获取一级分类
function get_one_category($gid='0') {
    global $city;
    $city_id = $city['id'];
	$today = strtotime(date('Y-m-d'));
	$condition_ev56_s_c = array(
		//'team_type' => 'normal',
		"begin_time <= '$today'",
		"end_time > '$today'",
	);
    $condition_ev56_s_c[] = "(city_ids like '%@$city_id@%' or city_ids like '%@0@%') or (city_ids = '' and city_id in(0,$city_id))";
	$row = DB::LimitQuery('category', array(
		'condition' => array( 'zone' => 'group','fid' => '0','display' => 'Y' ),
		'order' => 'ORDER BY sort_order DESC, id DESC',
	));	

	$category = array();
	
	foreach($row as $val){
	   $category[$val['id']]['id']    = $val['id'];
	   $category[$val['id']]['name']  = $val['name'];
	   $category[$val['id']]['fid']   = get_two_category($val['id']);
	}
	return $category;
}

function get_num($gid){
	
	$daytime = time();
	$condition = array( 
			"begin_time < {$daytime}",
			"end_time > {$daytime}",
			'group_id' => $gid,
			);
			
	$teams1 = DB::LimitQuery('team', array(
				'condition' => $condition,
				'order' => 'ORDER BY begin_time DESC, id DESC',
				));	

	return count($teams1);			
}

function get_num_f($gid){
	$daytime = time();
	$condition = array( 
			"begin_time < {$daytime}",
			"end_time > {$daytime}",
			'sub_id"' => $gid,
			);
	$teams1 = DB::LimitQuery('team', array(
				'condition' => $condition,
				'order' => 'ORDER BY begin_time DESC, id DESC',
				));	
	return count($teams1);			
}		
			
$cate = get_one_category();

foreach($cate as $val){
   $all_num +=  get_num($val['id']);
}

$pagetitle = '团购分类';


include template('m_seconds');
